var table;
var $;
var layer;
var form;
layui.use(['table', 'jquery', 'layer', 'form','laydate'], function () {
    table = layui.table;
    $ = layui.jquery;
    layer = layui.layer;
    form = layui.form;
    laydate = layui.laydate;
    //操作时间
    laydate.render({
        elem: '#searchDate',
        type: 'date',
        trigger: 'click'
    });

    getTable();
    //加载表格数据
    function getTable() {
        $.ajax({
            url:'/goodsTable/getGoodsJournals',
            type:'post',
            dataType:'json',
            data:{'type':1},
            success:function (data) {
                tablereload(data.data);
            }
        });
    }
    function tablereload(data) {
        console.log(data);
        var logTable = table.render({
            elem: "#root",
            data:data,
            toolbar: '#toptool',
            defaultToolbar: ['print', 'filter', 'exports'],
            limit: 10,
            page: {
                layout: ['count', 'prev', 'page', 'next', 'skip', 'refresh'],
                first: "首页",
                last: "尾页",
            },
            size: 'lg',
            cols: [[
                {type: 'checkbox', align: 'center', width: 60},
                {
                    type: 'numbers', title: '序号', align: 'center', width: 60, templet: function (data) {
                        return data.LAY_INDEX;
                    }
                },
                {field: 'updateName', title: '管理员名称', align: 'center'},
                {field: 'operationList', title: '操作列表', align: 'center'},
                {field: 'executionTime', title: '操作时间', align: 'center'},
                {field: 'remarks', title: '备注', align: 'center',templet:function (data) {
                        if(data.remarks == '' || data.remark == null){
                            data.remarks = '无内容';
                        }
                        return data.remarks;
                    }},
                {title: '操作', align: 'center', templet: function (data) {
                        var tem = '<a  href="javascript:delJournalById(' + data.id + ');" style="color:rgb(13,171,158)">删除</a>';
                        return tem;
                    }},
            ]]
        })
    }


    /*搜索*/
    form.on('submit(sub)', function (data) {
        console.log(data);
        console.log(data.field.operationType+",,"+data.field.executionTime);
        $.ajax({
            url:'/goodsTable/getGoodsJournals',
            type:'post',
            dataType:'json',
            data:{'type':1,'executionTime':data.field.executionTime,'operationType':data.field.operationType},
            success:function (data) {
                tablereload(data.data);
            }
        });
        return false;
    })

    /*删除*/
    delJournalById = function delJournalById(id) {
        console.log(layer);
        layer.confirm('是否确定删除此条数据', {
                icon: 3, title: '提示'
            },
            function (index) {
                $.ajax({
                    url: "/goodsTable/delJournalById",
                    type: "post",
                    dataType: "json",
                    data: {'id': id},
                    success: function (data) {
                        if (data.data) {
                            layer.alert("删除成功");
                            layer.close(index);
                            getTable();
                        } else {
                            layer.msg("删除失败");
                            layer.close(index);
                        }
                    }
                })

            }
        )
    }
    /*重置*/
    $("#reset").click(function () {
        var jsProduct = {'result': '1'}
        getTable(jsProduct);
    })
})

/*刷新*/
function Refresh() {
    location.reload();
}

/*跳转*/
function goBack() {
    parent.$('#quickHref').val('商品列表');
    parent.getQuick();
    return;
}